home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 19 / develop 19 code / SimpliFace_V2 / Sources / ObjModelTokens.cp < prev    next >
Encoding:
Text File  |  1994-05-01  |  19.1 KB  |  829 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ObjModelTokens.cp
  3.  
  4.     Contains:    Token classes implementation
  5.  
  6.  
  7.     Developed by:
  8.  
  9.     Paul G Smith (commstalk hq & Full Moon Software, Inc)
  10.  
  11.     you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  12.     BUT I prefer to be contacted by e-mail
  13.     AppleLink:     COMMSTALK.HQ
  14.     Internet:     COMMSTALK.HQ@applelink.apple.com
  15.  
  16.     "SimpliFace2" Sample code to accompany develop article
  17.     on techniques for controlling script inheritance.
  18.     
  19.     
  20.  
  21.  
  22.     Apple Event Object Model tokens for SimpliFace2
  23.  
  24. */
  25.  
  26.  
  27. #ifndef __MENUS__
  28. #include <Menus.h>
  29. #endif
  30. #ifndef __EVENTS__
  31. #include <Events.h>
  32. #endif
  33. #ifndef __WINDOWS__
  34. #include <Windows.h>
  35. #endif
  36. #ifndef __DIALOGS__
  37. #include <Dialogs.h>
  38. #endif
  39. #ifndef __QUICKDRAW__
  40. #include <Quickdraw.h>
  41. #endif
  42. #ifndef __MEMORY__
  43. #include <Memory.h>
  44. #endif
  45. #ifndef __FILES__
  46. #include <Files.h>
  47. #endif
  48. #ifndef __STANDARDFILE__
  49. #include <StandardFile.h>
  50. #endif
  51. #ifndef __SYSEQU__
  52. #include <SysEqu.h>
  53. #endif
  54. #ifndef __PLSTRINGFUNCS__
  55. #include <PLStringFuncs.h>
  56. #endif
  57.  
  58. #ifndef __AERegistry__
  59. #include <AERegistry.h>
  60. #endif
  61. #ifndef __ASREGISTRY__
  62. #include <ASRegistry.h>
  63. #endif
  64. #ifndef __APPLEEVENTS__
  65. #include <AppleEvents.h>
  66. #endif
  67. #ifndef __AEOBJECTS__
  68. #include <AEObjects.h>
  69. #endif
  70.  
  71. #ifndef __AEOBJECTPACKING__
  72. #include <AEPackObject.h>
  73. #endif
  74.  
  75. #ifndef __AEOMTOKENS__
  76. #include "ObjModelTokens.h"
  77. #endif
  78.  
  79. #ifndef __AEOMEVENTS__
  80. #include "ObjModelEvents.h"
  81. #endif
  82.  
  83. #ifndef __SCRIPTUTILS__
  84. #include "ScriptUtils.h"
  85. #endif
  86.  
  87.  
  88.  
  89. #pragma segment ObjectAccessors
  90.  
  91.  
  92.  
  93. // ------------
  94.  
  95.  
  96. // ------------
  97.  
  98. #pragma trace off
  99.  
  100. // utility routines
  101.  
  102. objModelTokenPtr ObjModelTokenFromDesc(AEDesc *theDesc)
  103. {
  104.     objModelTokenPtr    theToken = nil;
  105.     Size                actSize;
  106.     
  107.     if (theDesc->descriptorType == typeObjModelToken)
  108.         GetRawDataFromDescriptor(theDesc, (Ptr)&theToken, sizeof(theToken), &actSize);
  109.         
  110.     return theToken;
  111. }
  112.  
  113. OSErr DescFromObjModelToken(const objModelTokenPtr theToken, AEDesc *theDesc)
  114. {
  115.     return AECreateDesc(typeObjModelToken, (Ptr)&theToken, sizeof(theToken), theDesc);
  116. }
  117.  
  118.  
  119. // -------------------------------------------------------
  120.  
  121. #pragma segment ObjectAccessors
  122.  
  123. #pragma trace off
  124.  
  125.  
  126. TObjModelToken::TObjModelToken(void)
  127. {
  128.     fTokenClass = typeNull;
  129.     fIsProperty = false;
  130.     fPropertyID = typeNull;
  131.     fTheObject = NULL;
  132. }
  133.  
  134.  
  135. TObjModelToken::TObjModelToken(DescType theTokenClass,
  136.                                 TScriptableObject* theObj)
  137. {
  138.     fTokenClass = theTokenClass;
  139.     fIsProperty = false;
  140.     fPropertyID = typeNull;
  141.     fTheObject = theObj;
  142. }
  143.  
  144.  
  145. TObjModelToken::TObjModelToken(const TObjModelToken& oldObj)
  146. {
  147.     fTokenClass = oldObj.fTokenClass;
  148.     fIsProperty = oldObj.fIsProperty;
  149.     fPropertyID = oldObj.fPropertyID;
  150.     fTheObject = oldObj.fTheObject;
  151. }
  152.  
  153.  
  154. TObjModelToken& TObjModelToken::operator=(const TObjModelToken& oldObj)
  155. {
  156.     if (this != &oldObj)
  157.     {
  158.         fTokenClass = oldObj.fTokenClass;
  159.         fIsProperty = oldObj.fIsProperty;
  160.         fPropertyID = oldObj.fPropertyID;
  161.         fTheObject = oldObj.fTheObject;
  162.     }
  163.     return *this;
  164. }
  165.  
  166.  
  167. TObjModelToken::~TObjModelToken(void)
  168. {
  169.     // nothing to do!
  170. }
  171.  
  172.  
  173. TObjModelToken* TObjModelToken::MakeClone(void)
  174.     return new TObjModelToken(*this);
  175. }
  176.  
  177.  
  178. // support for object accessors
  179.  
  180.  
  181. TObjModelToken* TObjModelToken::MakeNewToken (DescType theTokenClass,
  182.                                             TScriptableObject* theObj)
  183. {
  184.     TObjModelToken    *resultToken = new TObjModelToken(theTokenClass, theObj);
  185.     
  186.     return resultToken;
  187. }
  188.  
  189.  
  190. OSErr TObjModelToken::ResolveElement(DescType desiredClass,
  191.                                     DescType keyForm,
  192.                                     AEDesc *keyData,
  193.                                     TObjModelToken **theResultToken)
  194. {
  195.     OSErr                 err = errAEEventNotHandled;
  196.     TScriptableObject     *theResultObj = NULL;
  197.     
  198.     // this function has been called because no derived class knows
  199.     // how to resolve the specified token
  200.     
  201.     // start by testing keyForm; 
  202.  
  203.     if (!fTheObject)    // can't do it if no object referenced!
  204.         return errAEEventNotHandled;
  205.     else if (keyForm == formName)
  206.     {
  207.         CStr255     nameStr = "";
  208.  
  209.         err = GetPStringFromDescriptor(keyData, (char *)&nameStr);
  210.         
  211.         if (err == noErr)
  212.             err = fTheObject->ResolveElementByName(desiredClass, nameStr, 
  213.                                                     &theResultObj);
  214.     } 
  215.     else if (keyForm == formAbsolutePosition)
  216.     {
  217.         short       index;
  218.  
  219.         err = GetIntegerFromDescriptor(keyData, &index);
  220.         if (index < 0)
  221.         {
  222.             long numElems;
  223.             
  224.             if (fTheObject->CountElements(desiredClass, &numElems) == 0)
  225.                 index = numElems + index + 1;
  226.         }
  227.         
  228.         if (err == noErr)
  229.             err = fTheObject->ResolveElementByIndex(desiredClass, index, 
  230.                                                     &theResultObj);
  231.     }
  232.     else
  233.         err = errAEBadKeyForm;
  234.         
  235.     if (err == noErr)
  236.     {
  237.         *theResultToken = MakeNewToken(desiredClass, theResultObj);
  238.     }
  239.     return err;
  240. }
  241.                                     
  242. OSErr TObjModelToken::ResolveProperty(DescType desiredClass,
  243.                                     DescType keyForm,
  244.                                     AEDesc *keyData,
  245.                                     TObjModelToken **theResultToken)
  246. {
  247.     OSErr             err = errAEEventNotHandled;
  248.     DescType          theProperty;
  249.     Size              actualSize;
  250.     
  251.     if (keyForm == formPropertyID)
  252.     {
  253.         GetRawDataFromDescriptor(keyData, (Ptr)&theProperty,
  254.                                  sizeof(theProperty), &actualSize);
  255.         
  256.         fIsProperty = true;
  257.         fPropertyID = theProperty;
  258.         
  259.         // make clone of this token and return reference to 
  260.         // it in theResultToken (requires use of copy constructors)
  261.         
  262.         *theResultToken = this->MakeClone();
  263.         
  264.         if (*theResultToken)
  265.             err = noErr;
  266.     }
  267.     
  268.     return err;
  269. }
  270.  
  271.  
  272. OSErr TObjModelToken::CallDispatchAppleEvent(AppleEvent *theEvent, 
  273.                                     AppleEvent *theReply, 
  274.                                     AEEventClass theEvtClass,
  275.                                     AEEventID theEvtID)
  276. {
  277.     return this->DispatchAppleEvent(theEvent, theReply, theEvtClass, theEvtID);
  278. }
  279.  
  280.  
  281. OSErr TObjModelToken::DispatchAppleEvent(AppleEvent *theEvent, 
  282.                                     AppleEvent *theReply, 
  283.                                     AEEventClass theEvtClass,
  284.                                     AEEventID theEvtID)
  285. {
  286.     OSErr             err = errAEEventNotHandled;
  287.     
  288.     if (!fTheObject)    // can't do it if no object referenced!
  289.         return err;
  290.  
  291.     if (theEvtClass == kASAppleScriptSuite && theEvtID == kASSubroutineEvent)
  292.     {
  293.         //Trace("Received AS subroutine event (not handled)\n");
  294.     }
  295.     else if (theEvtClass == kAEMiscStandards && theEvtID == kAEDoScript)
  296.     {
  297.         //Trace("Received Do Script event (not handled)\n");
  298.     }
  299.     else if (theEvtClass == kAECoreSuite || theEvtClass == kCoreEventClass)
  300.     {
  301.         switch (theEvtID)
  302.         {
  303.         case kAECountElements:
  304.             err = this->AECountElems(theEvent, theReply);
  305.             break;
  306.         case kAECreateElement:
  307.             err = this->AECreateElem(theEvent, theReply);
  308.             break;
  309.         case kAEDelete:
  310.             err = this->AEDeleteElem(theEvent, theReply);
  311.             break;
  312.         case kAEClose:
  313.             err = this->AECloseObject(theEvent, theReply);
  314.             break;
  315.         case kAEGetData:
  316.             err = this->AEGetObjectData(theEvent, theReply);
  317.             break;
  318.         case kAEOpen:
  319.             err = this->AEOpenObject(theEvent, theReply);
  320.             break;
  321.         case kAESetData:
  322.             err = this->AESetObjectData(theEvent, theReply);
  323.             break;
  324.         }
  325.     }
  326.     return err;
  327. }
  328.                         
  329.  
  330. // hooks into Apple Event handling, only override for special-purposes;
  331. // return noErr if Apple Event was handled within the hook function, or 
  332. // errAEEventNotHandled if it was not handled within the hook function
  333.  
  334. OSErr TObjModelToken::AECountElems        (AppleEvent *theEvent, 
  335.                                         AppleEvent *theReply)
  336. {
  337.     OSErr                 err = errAEEventNotHandled;
  338.     AEDesc                resultDesc;
  339.     Size                theSize;
  340.     DescType            theType, desiredClass;
  341.     long                result;
  342.  
  343.     InitAEDescs(&resultDesc, kEndOfList);
  344.     
  345.     err = AEGetParamPtr(theEvent, keyAEObjectClass, typeType, &theType,
  346.                         (Ptr)&desiredClass, sizeof(DescType), &theSize);
  347.     
  348.     if (err == noErr)
  349.         err = fTheObject->CountElements(desiredClass, &result);
  350.         
  351.     if (err == noErr)
  352.         err = AECreateDesc(typeLongInteger, &result, sizeof(long), &resultDesc);
  353.         
  354.     if (err == noErr && theReply->descriptorType != typeNull)
  355.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  356.     
  357.     DisposeAEDescs(&resultDesc, kEndOfList);
  358.     
  359.     return err;
  360. }
  361.  
  362. OSErr TObjModelToken::AECreateElem        (AppleEvent *theEvent, 
  363.                                         AppleEvent *theReply)
  364. {
  365.     //     get insertionloc
  366.     //        resolve insertion point
  367.     //     get desired object class
  368.     //  ask object at insertion point to create new object
  369.     //    get new object's data (optional param)
  370.     //        save data
  371.     //    get new object's properties record  (optional param)
  372.     //        save properties
  373.     //    ask new object to create it's own object specifier
  374.     //    return object specifier as result
  375.     OSErr                 err = errAEEventNotHandled;
  376.     AEDesc                resultDesc, dataObject;
  377.     AEDesc                insLocParam, insLocObject, theTokenDesc;
  378.     AERecord            insLocRec, dataPropParam;
  379.     TObjModelToken         *theToken = NULL;
  380.     Size                theSize;
  381.     DescType            theType, position;
  382.     DescType            theClass;
  383.     
  384.     InitAEDescs(&insLocParam, &insLocRec, &insLocObject, &theTokenDesc,
  385.                 &resultDesc, &dataObject, &dataPropParam, kEndOfList);
  386.     
  387.     err = AEGetParamPtr(theEvent, keyAEObjectClass, typeType, &theType,
  388.                         (Ptr)&theClass, sizeof(DescType), &theSize);
  389.     if (err == noErr)
  390.         err = AEGetParamDesc(theEvent, keyAEInsertHere, typeInsertionLoc, &insLocParam);
  391.     if (err)
  392.     {
  393.         TObjModelToken    *aApplicationToken = NULL;
  394.         
  395.         position = kAEEnd;
  396.         err = MakeAppToken(&aApplicationToken);
  397.         if (err == noErr)
  398.         {
  399.             theToken = aApplicationToken;
  400.             DescFromObjModelToken(theToken, &theTokenDesc);
  401.         }
  402.     }
  403.     else
  404.     {
  405.         // coerce the insertion loc record to an AE record.
  406.         err = AECoerceDesc(&insLocParam, typeAERecord, &insLocRec);
  407.         if (err == noErr)
  408.             err = AEGetKeyPtr(&insLocRec, keyAEPosition, typeEnumeration, &theType, 
  409.                                 (Ptr)&position, sizeof(DescType), &theSize);
  410.         if (err == noErr)    //    Get the object reference
  411.             err = AEGetKeyDesc(&insLocRec, keyAEObject, 
  412.                                 typeWildCard, &insLocObject);
  413.     
  414.         if (err == noErr)
  415.         {
  416.             err = AEResolve(&insLocObject, kAEIDoMinimum, &theTokenDesc);
  417.             
  418.             if (err == noErr)
  419.                 theToken = ObjModelTokenFromDesc(&theTokenDesc);
  420.         }
  421.     }
  422.  
  423.     if (theToken)
  424.     {
  425.         TScriptableObject     *theNewObj = NULL;
  426.         TObjModelToken        *theNewToken = NULL;
  427.         TScriptableObject    *containerObj = NULL;
  428.         AERecord            *dataPropPtr = NULL;
  429.  
  430.         err = theToken->GetTokenObj()->ResolveContainer(&containerObj);
  431.  
  432.         if (position == kAEReplace && 
  433.              (theToken->GetTokenClass() == cApplication
  434.               || theToken->GetTokenClass() == cDocument))
  435.             err = errAEEventNotHandled;
  436.         else
  437.         {
  438.             err = AEGetParamDesc(theEvent, keyAEData, typeWildCard, &dataObject);
  439.             err = AEGetParamDesc(theEvent, keyAEPropData, typeAERecord, 
  440.                                     &dataPropParam);
  441.             if (err == noErr)
  442.                 dataPropPtr = &dataPropParam;
  443.             // ignore errors if above calls fail
  444.             err = theToken->GetTokenObj()->CreateNewElement(theClass, position, 
  445.                                             &dataObject, dataPropPtr,
  446.                                             containerObj, &theNewObj);
  447.             if (err == noErr)
  448.                 theNewToken = MakeNewToken(theClass, theNewObj);
  449.                 
  450.             if (err == noErr && theNewToken)
  451.                 theNewToken->GetTokenObj()->GetObjectSpecifier(&resultDesc);
  452.             if (theNewToken)
  453.                 delete theNewToken;
  454.         }
  455.     }
  456.     
  457.     if (err == noErr && (resultDesc.descriptorType != typeNull) 
  458.         && (theReply->descriptorType != typeNull))
  459.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  460.     
  461.     AEDisposeToken(&theTokenDesc); // DO NOT CALL until done with 'theToken'
  462.     DisposeAEDescs(&insLocParam, &insLocRec, &insLocObject,
  463.                     &resultDesc, &dataObject, &dataPropParam, kEndOfList);
  464.     return err;
  465. }
  466.  
  467. OSErr TObjModelToken::AEDeleteElem        (AppleEvent *theEvent, 
  468.                                         AppleEvent *theReply)
  469. {
  470.     OSErr         err = fTheObject->DeleteObject();
  471.     
  472.     return err;
  473. }
  474.  
  475. OSErr TObjModelToken::AECloseObject       (AppleEvent *theEvent, 
  476.                                         AppleEvent *theReply)
  477. {
  478.     return fTheObject->CloseObject();
  479. }
  480.  
  481. OSErr TObjModelToken::AEGetObjectData   (AppleEvent *theEvent, 
  482.                                         AppleEvent *theReply)
  483. {
  484.     OSErr         err = errAEEventNotHandled;
  485.     AEDesc        resultDesc;
  486.  
  487.     resultDesc.dataHandle = NULL;
  488.  
  489.     if (fIsProperty)
  490.     {
  491.         DescType        wantType, actualType;
  492.         Size            actualSize;
  493.         
  494.         err = AEGetParamPtr(theEvent, keyAERequestedType, typeType, &actualType,
  495.                             (Ptr)&wantType, sizeof(DescType), &actualSize);
  496.         if (err)
  497.             wantType = typeWildCard;
  498.         
  499.         err = fTheObject->GetProperty(fPropertyID, wantType, &resultDesc);
  500.     }
  501.     else
  502.     {
  503.         err = fTheObject->GetData(&resultDesc);
  504.         if (err == errAEEventNotHandled)
  505.             err = AEGetParamDesc(theEvent, keyDirectObject, 
  506.                                     typeObjectSpecifier, &resultDesc);
  507.     }
  508.     
  509.     if (err == noErr && theReply->descriptorType != typeNull)
  510.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  511.     
  512.     AEDisposeDesc(&resultDesc);
  513.     
  514.     return err;
  515. }
  516.  
  517. OSErr TObjModelToken::AEOpenObject      (AppleEvent *theEvent, 
  518.                                         AppleEvent *theReply)
  519. {
  520.     return fTheObject->OpenObject();
  521. }
  522.  
  523. OSErr TObjModelToken::AESetObjectData   (AppleEvent *theEvent, 
  524.                                         AppleEvent *theReply)
  525. {
  526.     OSErr     err = errAEEventNotHandled;
  527.     AEDesc    dataDesc;
  528.  
  529.     dataDesc.dataHandle = NULL;
  530.     
  531.     err = AEGetParamDesc(theEvent, keyAEData, typeWildCard, &dataDesc);
  532.     
  533.     if (fIsProperty)
  534.         err = fTheObject->SetProperty(fPropertyID, &dataDesc);
  535.     else
  536.         err = fTheObject->SetData(&dataDesc);
  537.         
  538.     AEDisposeDesc(&dataDesc);
  539.     
  540.     return err;
  541. }
  542.  
  543.  
  544. // -------------------------------------------------------
  545.  
  546.  
  547.  
  548. #pragma segment Main
  549.     
  550. // object accessors 
  551.  
  552.  
  553. OSErr MakeAppToken(TObjModelToken** theApplicationToken)
  554. {
  555.     OSErr               err = errAEEventNotHandled;
  556.  
  557.     *theApplicationToken = new TObjModelToken(cApplication, gSimpliFace2);
  558.         
  559.     if (theApplicationToken)
  560.         err = 0;
  561.     else
  562.         err = -108; // out of memory
  563.  
  564.     return err;
  565. }
  566.  
  567.  
  568. pascal OSErr PropertyFromNullAccessor   (DescType desiredClass,
  569.                                                 AEDesc *containerToken,
  570.                                                 DescType containerClass,
  571.                                                 DescType keyForm,
  572.                                                 AEDesc *keyData,
  573.                                                 AEDesc *theToken,
  574.                                                 long theRefCon)
  575. {
  576.     OSErr               err = errAEEventNotHandled;
  577.     objModelTokenPtr     theResolvedToken = NULL;
  578.     TObjModelToken        *aApplicationToken = NULL;
  579.  
  580.     if ((desiredClass != cProperty) || (containerClass != typeNull))
  581.         return(errAEWrongDataType);
  582.     
  583.     // we assume property being requested is an application property, 
  584.     // and create a temporary application token
  585.     err = MakeAppToken(&aApplicationToken);
  586.     if (err == noErr)
  587.     {
  588.         err = DescFromObjModelToken((const objModelTokenPtr)aApplicationToken, theToken);
  589.     
  590.         if (err == noErr && theToken)
  591.         {    // ask the temporary application token to resolve the property
  592.             // (this step creates a new token)
  593.             err = aApplicationToken->ResolveProperty(desiredClass, keyForm, keyData, &theResolvedToken);
  594.             if (err == noErr && theResolvedToken)
  595.             {
  596.                 err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  597.             }
  598.         }
  599.         
  600.         if (aApplicationToken)
  601.             delete aApplicationToken;    // dispose of the temporary application token
  602.     }
  603.     return err;
  604. }
  605.                                                 
  606.  
  607. pascal OSErr AppTokenFromNullAccessor  (DescType desiredClass,
  608.                                         AEDesc *containerToken,
  609.                                         DescType containerClass,
  610.                                         DescType keyForm,
  611.                                         AEDesc *keyData,
  612.                                         AEDesc *theToken,
  613.                                         long theRefCon)
  614. {
  615.     OSErr               err = errAEEventNotHandled;
  616.     TObjModelToken    *aApplicationToken = NULL;
  617.     
  618.     if ((desiredClass != cApplication) || (containerClass != typeNull))
  619.         return(errAEWrongDataType);
  620.     
  621.     err = MakeAppToken(&aApplicationToken);
  622.  
  623.     if (err == noErr)
  624.         err = DescFromObjModelToken((const objModelTokenPtr)aApplicationToken, 
  625.                                     theToken);
  626.      
  627.     return(err);
  628. }
  629.                                                 
  630.  
  631. pascal OSErr StdObjectFromNullAccessor   (DescType desiredClass,
  632.                                             AEDesc *containerToken,
  633.                                             DescType containerClass,
  634.                                             DescType keyForm,
  635.                                             AEDesc *keyData,
  636.                                             AEDesc *theToken,
  637.                                             long theRefCon)
  638. {
  639.     OSErr               err = errAEEventNotHandled;
  640.     TObjModelToken    *aApplicationToken = NULL;
  641.     objModelTokenPtr     theResolvedToken = NULL;
  642.     
  643.     if (containerClass != typeNull)
  644.         return(errAEWrongDataType);
  645.     
  646.     err = MakeAppToken(&aApplicationToken);
  647.     
  648.     if (err == noErr)
  649.     {
  650.         err = aApplicationToken->ResolveElement(desiredClass, keyForm, 
  651.                                                 keyData, &theResolvedToken);
  652.         if (err == noErr && theResolvedToken)
  653.         {
  654.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, 
  655.                                         theToken);
  656.         }
  657.         delete aApplicationToken;
  658.     }
  659.  
  660.     return(err);
  661. }
  662.                                                 
  663.  
  664.                                                 
  665.  
  666. pascal OSErr StdObjectAccessor (DescType desiredClass,
  667.                                         AEDesc *containerToken,
  668.                                         DescType containerClass,
  669.                                         DescType keyForm,
  670.                                         AEDesc *keyData,
  671.                                         AEDesc *theToken,
  672.                                         long theRefCon)
  673. {
  674.     OSErr err = errAEEventNotHandled;
  675.     objModelTokenPtr theContToken = ObjModelTokenFromDesc(containerToken);
  676.     objModelTokenPtr theResolvedToken = nil;
  677.     
  678.     if (theToken)
  679.     {
  680.         err = theContToken->ResolveElement(desiredClass, keyForm, keyData, &theResolvedToken);
  681.         if ((err == 0) && theResolvedToken)
  682.         {
  683.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  684.         }
  685.             
  686.     }
  687.     
  688.     return err;
  689. }
  690.                                         
  691.                                     
  692. pascal OSErr StdPropertyAccessor(DescType desiredClass,
  693.                                         AEDesc *containerToken,
  694.                                         DescType containerClass,
  695.                                         DescType keyForm,
  696.                                         AEDesc *keyData,
  697.                                         AEDesc *theToken,
  698.                                         long theRefCon)
  699. {
  700.     OSErr err = errAEEventNotHandled;
  701.     objModelTokenPtr theContToken = ObjModelTokenFromDesc(containerToken);
  702.     objModelTokenPtr theResolvedToken = nil;
  703.     
  704.     if (theContToken && theToken)
  705.     {
  706.         err = theContToken->ResolveProperty(desiredClass, keyForm, keyData, &theResolvedToken);
  707.         if ((err == 0) && theResolvedToken)
  708.         {
  709.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  710.         }
  711.             
  712.     }
  713.     
  714.     return err;
  715. }
  716.                                         
  717.  
  718. // object support callbacks
  719.  
  720. pascal OSErr StdCountProc        (DescType desiredClass,
  721.                                         DescType containerClass,
  722.                                         AEDesc *containerToken,
  723.                                         long *result)
  724. {
  725.     OSErr                 err = errAEEventNotHandled;
  726.     objModelTokenPtr     theToken = ObjModelTokenFromDesc(containerToken);
  727.  
  728.     if (theToken)
  729.         err = theToken->GetTokenObj()->CountElements(desiredClass, result);
  730.     
  731.     return err;
  732. }
  733.                                         
  734.                                     
  735. pascal OSErr StdCompareProc    (DescType comparisonOperator,
  736.                                         AEDesc object,
  737.                                         DescType objOrDescToCompare,
  738.                                         Boolean& result)
  739. {
  740.     OSErr err = errAEEventNotHandled;
  741.     
  742.     
  743.     return err;
  744. }
  745.  
  746.                                             
  747. pascal OSErr StdDisposeToken   (AEDesc *unneededToken)
  748. {
  749.     OSErr err =    errAEEventNotHandled;
  750.  
  751.     if (unneededToken)
  752.     {
  753.         objModelTokenPtr theToken = ObjModelTokenFromDesc(unneededToken);
  754.         if (theToken)
  755.         {
  756.             delete theToken;
  757.             err = AEDisposeDesc(unneededToken);
  758.             unneededToken->dataHandle = NULL; // in case OSL deletes us twice
  759.         }
  760.     }
  761.     return err;
  762. }
  763.  
  764.  
  765.  
  766. // -------setup
  767.  
  768.  
  769.  
  770. OSErr InstallAccessors(void);
  771.  
  772. OSErr DeInstallAccessors(void);
  773.  
  774.  
  775. // #pragma segment ObjectInit
  776.  
  777. // set up object model handlers
  778. OSErr SFinitAEobjects(void)
  779. {
  780.     OSErr err = 0;
  781.     
  782.     err = InstallAccessors();
  783.     
  784.     return err;
  785. }
  786.  
  787. // detach object model handlers & shut down
  788. OSErr SFendAEobjects(void)
  789. {
  790.     OSErr err = 0;
  791.     
  792.     err = DeInstallAccessors();
  793.     
  794.     return err;
  795. }
  796.  
  797.  
  798. // installation
  799.  
  800. OSErr InstallAccessors(void)
  801. {
  802.     OSErr err = 0;
  803.     
  804.     if (err == noErr) err = AEInstallObjectAccessor(cApplication, typeNull, (accessorProcPtr)&AppTokenFromNullAccessor, (long)cApplication, false);
  805.     if (err == noErr) err = AEInstallObjectAccessor(typeWildCard, typeNull, (accessorProcPtr)&StdObjectFromNullAccessor, 0, false);
  806.     if (err == noErr) err = AEInstallObjectAccessor(typeWildCard, typeObjModelToken, (accessorProcPtr)&StdObjectAccessor, 0, false);
  807.  
  808.     if (err == noErr) err = AEInstallObjectAccessor(cProperty, typeNull, (accessorProcPtr)&PropertyFromNullAccessor, (long)cProperty, false);
  809.     if (err == noErr) err = AEInstallObjectAccessor(cProperty, typeObjModelToken, (accessorProcPtr)&StdPropertyAccessor, (long)cProperty, false);
  810.     
  811.     if (err == noErr) err = AESetObjectCallbacks(   (compareProcPtr)&StdCompareProc, 
  812.                                             (countProcPtr)&StdCountProc, 
  813.                                             (disposeTokenProcPtr)&StdDisposeToken,
  814.                                             nil, nil, nil, nil);
  815.     
  816.     return err;
  817. }
  818.  
  819. OSErr DeInstallAccessors(void)
  820. {
  821.     OSErr err = 0;
  822.  
  823.     
  824.     return err;
  825. }
  826.  
  827.  
  828.